import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;


public class MyStack {
    public int[] elem;
    public int size;

    public MyStack() {
        this.elem = new int[10];
    }


    //判断栈是否已经装满
    public boolean isEmpty() {
        return size == elem.length;
    }


    //入栈操作
    public void push(int val) {
        if (isEmpty()) {
            elem = Arrays.copyOf(elem, 2 * elem.length);
        }
        elem[size] = val;
        size++;
    }

    //出栈
    public void pop() {

    }

    public int[] smallestK(int[] arr, int k) {
        int[] tmp = new int[k];
        if (k == 0) return tmp;
        PriorityQueue<Integer> maxHeap = new PriorityQueue<>(new IntCmp());

        //1. 把前 k 个元素放进堆中
        for (int i = 0; i < k; i++) {
            maxHeap.offer(arr[i]);
        }

        //2. 遍历剩下的 N-K 个元素
        for (int i = k; i < arr.length; i++) {
            int val = maxHeap.peek();
            if (val > arr[i]) {
                maxHeap.poll();
                maxHeap.offer(arr[i]);
            }
        }
        for (int i = 0; i < k; i++) {
            tmp[i] = maxHeap.poll();
        }
        return tmp;
    }

    class IntCmp implements Comparator<Integer> {

        @Override
        public int compare(Integer o1, Integer o2) {
            return o1.compareTo(o2);
        }
    }

}


class solution {


}



